<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.*,util.*,model.*,control.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body> 
<%
	request.setCharacterEncoding("utf-8");
	/*
	*查看用户名是否存在 
	*@author hujin
	*2011-12-8
	*
	*/
	String userN = ParamUtil.getString(request,"userN");
	int id = ParamUtil.getInt(request,"id");
	String oldUsername = ParamUtil.getString(request,"oldUsername");
	System.out.println(oldUsername);
	others xx = new others();
	//System.out.println("1111");
	if(xx.IsUserExist(userN)) { 
	//System.out.println("2222");
		if(!userN.equals(oldUsername)){
	%>
<script language="javascript">
	     alert("用户名已存在");
	     window.location.href="student_update.jsp?id=<%=id%>";
	     </script>
<%
	}
	//return ;
	}
	
	String sna = ParamUtil.getString(request,"sna");
	String pas = ParamUtil.getString(request,"pas");
	String sx = ParamUtil.getString(request,"sx");
	String sc = ParamUtil.getString(request,"sc");
	String cl = ParamUtil.getString(request,"cl");
	String ma = ParamUtil.getString(request,"ma");
	String al = ParamUtil.getString(request,"al");
	if(userN==null||pas==null||userN==""||pas==""){
	%>
<script language="javascript">
	     alert("用户名密码不能为空");
	     window.location.href="student_update.jsp";
	     </script>
<%
	}
	
	
	Student student = new Student();
	StudentControl scc = new StudentControl();
	
	student.setUsername(userN);
	
	student.setStudentName(sna);
	student.setPassword(pas);
	student.setSex(sx);
	student.setSchool(sc);
	student.setClasses(cl);
	student.setMajor(ma);
	student.setAlt1(al);
	
	if(scc.updateStudent(student, id))
	{
	%>
		
	<script language="javascript">
     alert("修改成功");
     window.location.href="student_index.jsp";
    </script>
	
	<%
	} else { 
	%>
	
	<script language="javascript">
     alert("修改失败");
     window.location.href="student_update.jsp?id=<%=id%>";
    </script>
	<%} %>
	



</body>
</html>